package com.example.home.youthstation;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;

import java.util.List;

public class YiZhanApter extends RecyclerView.Adapter<YiZhanApter.MyHoldy> {

    private Context context ;
    private List<YouthBean.DataBean> list;

    public YiZhanApter(Context context, List<YouthBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_hot,null);
        return new MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        Glide.with(context).load(list.get(position).getImgUrl()).into(holder.iv_hot_pic);
        holder.tv_hot_title.setText(list.get(position).getName());
        holder.iv_hot_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,StationDetailsActivity.class);
                intent.putExtra("DataBeanId",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 3;
    }

    public class MyHoldy extends RecyclerView.ViewHolder {

        private ImageView iv_hot_pic;
        private TextView tv_hot_title;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            iv_hot_pic = itemView.findViewById(R.id.iv_hot_pic);
            tv_hot_title = itemView.findViewById(R.id.tv_hot_title);
        }
    }
}
